export const isDesktop = () => {
    return !!window.ipcRenderer;
};

export const getProcessNodeEnv = () => {
    return window?.process?.NODE_ENV;
};

/**
 * 
 * @param {string} eventName 
 * @param  {...any} args 
 */
export const ipcRendererSend = (eventName, ...args) => {
    window.ipcRenderer?.send(eventName, ...args);
};

/**
 * 
 * @param {string} eventName 
 * @param  {...any} args 
 */
export const ipcRendererSendSync = (eventName, ...args) => {
    return window.ipcRenderer?.sendSync(eventName, ...args);
};

/**
 * 
 * @param {string} eventName 
 * @param  {...any} args 
 */
export const ipcRendererInvoke = (eventName, ...args) => {
    try {
        return window.ipcRenderer?.invoke(eventName, ...args);
    } catch (error) {
        console.error(`Error invoking IPC: ${eventName}`, error);
        return null;
    }
};

/**
 * 
 * @param {string} eventName 
 * @param  {(...args) => void} listener 
 */
export const ipcRendererOn = (eventName, listener) => {
    window.ipcRenderer?.on(eventName, listener);
};

/**
 * 
 * @param {string} eventName 
 * @param  {(...args) => void} listener 
 */
export const ipcRendererOnce = (eventName, listener) => {
    window.ipcRenderer?.once(eventName, listener);
};

/**
 * 
 * @param {string} eventName 
 * @param  {(...args) => void} listener 
 */
export const ipcRendererRemoveListener = (eventName, listener) => {
    window.ipcRenderer?.removeListener(eventName, listener);
};